package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource
    IserveService serveService;


    /**
     * @description: 区域服务列表
     * @author: xushuaihang
     * @Date: 2024/8/16 15:54
     * @param:
     * @param servePageQueryReqDTO
     * @return: com.jzo2o.common.model.PageResult<com.jzo2o.foundations.model.dto.response.ServeResDTO>
    **/
    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {

        PageResult<ServeResDTO> pageResult = serveService.page(servePageQueryReqDTO);

        return pageResult;
    }


    /**
     * @description: 区域服务添加
     * @author: xushuaihang
     * @Date: 2024/8/16 15:54
     * @param:
     * @param serveUpsertReqDTOList
     * @return: void
    **/
    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {

        serveService.add(serveUpsertReqDTOList);

    }


    /**
     * @description: 区域服务价格修改
     * @author: xushuaihang
     * @Date: 2024/8/16 16:33
     * @param:
     * @param id
     * @param price
     * @return: void
    **/
    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
            })
    public void update(@PathVariable("id") Long id,
                        @RequestParam("price") BigDecimal price) {

       serveService.updatePrice(id, price);

    }


    /**
     * @description: 区域服务上架
     * @author: xushuaihang
     * @Date: 2024/8/16 16:33
     * @param:
     * @param id
     * @return: void
    **/
    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            })
    public void onSale(@PathVariable("id") Long id) {

        serveService.onSale(id);

    }


    @DeleteMapping("/{id}")
    public void remove(@PathVariable(name = "id") Long id){

        serveService.remove(id);

    }
}
